//
//  AIFSetNewPwdManager.m
//  PywSdk
//
//  Created by smallwave on 16/8/25.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "AIFSetNewPwdManager.h"
#import "PywRSAUtil.h"
#import "PywSdk+login.h"

@implementation AIFSetNewPwdManager

NSString *const SetNewPwd_OldPwd = @"old_pwd";
NSString *const SetNewPwd_NewPwd = @"new_pwd";
NSString *const SetNewPwd_UserName = @"username";
NSString *const SetNewPwd_Tid = @"tid";
NSString *const SetNewPwd_Sign = @"sign";
NSString *const SetNewPwd_GameId = @"gameid";
NSString *const SetNewPwd_PassportToken = @"passport_token";
NSString *const SetNewPwd_Token = @"token";

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.child = self;
        self.paramSource = self;
        self.validate = self;
    }
    return self;
}


#pragma mark - ETAPIManager
- (NSString *)methodName
{
    return URL_SETNEWPWD;
}

- (ETAPIManagerRequestType)requestType
{
    return ETAPIManagerRequestTypePost;
}


- (NSString *)seriviceType
{
    return [PywAppInfo sharedAppInfo].seriviceType;
}


#pragma mark - ETAPIManagerParamSourceDelegate
- (NSDictionary *)paramsForApi:(ETApiBaseManager *)manager
{
    NSString *username = self.username;
    NSString *tid = [PywAppInfo sharedAppInfo].tid;
    
    NSString * apiSecret2 = [AppUtil getApiSecret2:tid apiSecret:[PywAppInfo sharedAppInfo].apisecret];
    NSString *sign = [NSString stringWithFormat:@"%@%@%@%@", self.old_pwd, self.news_pwd, username, apiSecret2];
    sign = [PywCipherUtils md5:sign];
    
    NSString *old_pwd = [PywRSAUtil encryptString:self.old_pwd];;
    NSString *news_pwd = [PywRSAUtil encryptString:self.news_pwd];
    NSString * gameid = [PywAppInfo sharedAppInfo].gameId;
    
    MutableDictionary *param = [[MutableDictionary alloc] init];
    if ([username isEqualToString:[PywPlatformMain sharedPlatformMain].passport]) {
        NSString *passport_token = [PywPlatformMain sharedPlatformMain].passport_Token;
        [param setObject:passport_token forKey:SetNewPwd_PassportToken];
    } else {
        NSString *token = [PywPlatformMain sharedPlatformMain].token;
        [param setObject:token forKey:SetNewPwd_Token];
    }
    
    [param setObject:username forKey:SetNewPwd_UserName];
    [param setObject:tid forKey:SetNewPwd_Tid];
    [param setObject:sign forKey:SetNewPwd_Sign];
    [param setObject:old_pwd forKey:SetNewPwd_OldPwd];
    [param setObject:news_pwd forKey:SetNewPwd_NewPwd];
    [param setObject:gameid forKey:SetNewPwd_GameId];
    return param;
}

#pragma mark - ETAPIManagerValidator
- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithParamsData:(NSDictionary *)data{
    return YES;
}

- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithCallBackData:(NSDictionary *)data{
    return YES;
}

@end
